package com.ruoyi.jksd.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.jksd.domain.XyBusinessConfig;
import com.ruoyi.jksd.service.IXyBusinessConfigService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 交易控制Controller
 *
 * @author ruoyi
 * @date 2024-05-27
 */
@RestController
@RequestMapping("/busconfig/busconfig")
public class XyBusinessConfigController extends BaseController {
    @Autowired
    private IXyBusinessConfigService xyBusinessConfigService;

    /**
     * 查询交易控制列表
     */
    @PreAuthorize("@ss.hasPermi('busconfig:busconfig:list')")
    @GetMapping("/list")
    public TableDataInfo list(XyBusinessConfig xyBusinessConfig) {
        startPage();
        List<XyBusinessConfig> list = xyBusinessConfigService.selectXyBusinessConfigList(xyBusinessConfig);
        return getDataTable(list);
    }

    /**
     * 查询交易控制列表
     */
    @GetMapping("/listRechargeInfo")
    public AjaxResult listRechargeInfo() {
        startPage();
        List<XyBusinessConfig> list = xyBusinessConfigService.selectXyBusinessConfigList(null);
        XyBusinessConfig xyBusinessConfig = new XyBusinessConfig();
        xyBusinessConfig.setUsdtAddress(list.get(0).getUsdtAddress());
        return AjaxResult.success(xyBusinessConfig);
    }


    /**
     * 导出交易控制列表
     */
    @PreAuthorize("@ss.hasPermi('busconfig:busconfig:export')")
    @Log(title = "交易控制", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, XyBusinessConfig xyBusinessConfig) {
        List<XyBusinessConfig> list = xyBusinessConfigService.selectXyBusinessConfigList(xyBusinessConfig);
        ExcelUtil<XyBusinessConfig> util = new ExcelUtil<XyBusinessConfig>(XyBusinessConfig.class);
        util.exportExcel(response, list, "交易控制数据");
    }

    /**
     * 获取交易控制详细信息
     */
    @PreAuthorize("@ss.hasPermi('busconfig:busconfig:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(xyBusinessConfigService.selectXyBusinessConfigById(id));
    }

    /**
     * 新增交易控制
     */
    @PreAuthorize("@ss.hasPermi('busconfig:busconfig:add')")
    @Log(title = "交易控制", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody XyBusinessConfig xyBusinessConfig) {
        return toAjax(xyBusinessConfigService.insertXyBusinessConfig(xyBusinessConfig));
    }

    /**
     * 修改交易控制
     */
    @PreAuthorize("@ss.hasPermi('busconfig:busconfig:edit')")
    @Log(title = "交易控制", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody XyBusinessConfig xyBusinessConfig) {
        return toAjax(xyBusinessConfigService.updateXyBusinessConfig(xyBusinessConfig));
    }

    /**
     * 删除交易控制
     */
    @PreAuthorize("@ss.hasPermi('busconfig:busconfig:remove')")
    @Log(title = "交易控制", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(xyBusinessConfigService.deleteXyBusinessConfigByIds(ids));
    }
}
